#include "SSD1306Wire.h"
SSD1306Wire display(0x3c, 2, 14);
#include <dht11.h>

dht11 DHT11;

const uint8_t wen[] = {
    0x00, 0x00, 0xC4, 0x1F, 0x48, 0x10, 0x48, 0x10, 0xC1, 0x1F, 0x42, 0x10, 0x42, 0x10, 0xC8, 0x1F,
    0x08, 0x00, 0xE4, 0x3F, 0x27, 0x25, 0x24, 0x25, 0x24, 0x25, 0x24, 0x25, 0xF4, 0x7F, 0x00, 0x00,
    /*"温",0*/};
const uint8_t du[] = {
    0x80, 0x00, 0x00, 0x01, 0xFC, 0x7F, 0x44, 0x04, 0x44, 0x04, 0xFC, 0x3F, 0x44, 0x04, 0x44, 0x04,
    0xC4, 0x07, 0x04, 0x00, 0xF4, 0x0F, 0x24, 0x08, 0x42, 0x04, 0x82, 0x03, 0x61, 0x0C, 0x1C, 0x70, /*"度",1*/
};
const uint8_t shi[] = {
    0x00, 0x00, 0xE4, 0x1F, 0x28, 0x10, 0x28, 0x10, 0xE1, 0x1F, 0x22, 0x10, 0x22, 0x10, 0xE8, 0x1F,
    0x88, 0x04, 0x84, 0x04, 0x97, 0x24, 0xA4, 0x14, 0xC4, 0x0C, 0x84, 0x04, 0xF4, 0x7F, 0x00, 0x00,
    /*"湿",2*/};

const uint8_t wenduji[] = {

    0x00, 0x00, 0xC0, 0x05, 0x40, 0x39, 0x40, 0x09, 0x40, 0x39, 0x40, 0x01, 0x40, 0x01, 0x40, 0x01,
    0x40, 0x01, 0xC0, 0x01, 0xC0, 0x01, 0xE0, 0x03, 0xE0, 0x03, 0xE0, 0x03, 0xE0, 0x03, 0x00, 0x00,
    

};

void setup()
{
  
  Serial.begin(115200); 
  display.init();
  Serial.println("\n");
  Serial.println("esp8266读取DHT11传感器数值 ");
  Serial.println("串口会分别打印当前湿度（%），当前摄氏度温度，当前华氏度温度和当前开式温度 ");
  Serial.print("DHT11库文件版本: ");
  Serial.println(DHT11LIB_VERSION);
  Serial.println();
}

void readDhtAndShow(int dhtIo)
{

  DHT11.read(dhtIo);
  
  display.flipScreenVertically();
  
  display.clear();
 
  display.drawIco16x16(0, 0, wen, 0);
  display.drawIco16x16(20, 0, du, 0);

  display.drawString(40, 0, String(DHT11.temperature));

  display.drawIco16x16(0, 20, shi, 0);
  display.drawIco16x16(20, 20, du, 0);
  display.drawString(40, 20, String(DHT11.humidity));

  display.drawIco16x16(60, 10, wenduji, 0);
  display.display();
  delay(500);
}

int dhtIo = 5;

void testRead(int dhtIo)
{
  DHT11.read(dhtIo);
  Serial.printf("dhtIo:  %d\n", dhtIo);
  
  Serial.print("当前湿度 (%): ");
  Serial.println((float)DHT11.humidity, 2);

  Serial.print("当前温度 (℃): ");
  Serial.println((float)DHT11.temperature, 2);
  dhtIo++;
  delay(500);
}


void loop()
{

  readDhtAndShow(dhtIo);
}
